package com.yoomiito.app.ui.my.teamallowance

import android.os.Bundle
import com.yoomiito.app.Constant
import com.yoomiito.app.model.my.MyTodayOrderInfo
import com.yoomiito.app.ui.fragment.my.MyOrderBaseFragment

class TeamAllowanceOrderFragment : MyOrderBaseFragment<TeamAllowanceOrderFmPresenter>(){

    private lateinit var mAdapter: TeamAllowanceOrderAdapter
    private var type: Int = 0
    override fun getEmptyContent(): String = "未购买商品"

    override fun newP(): TeamAllowanceOrderFmPresenter = TeamAllowanceOrderFmPresenter()

    override fun initData(savedInstanceState: Bundle?) {
        super.initData(savedInstanceState)
        if (arguments != null) {
            type = arguments!!.getInt(Constant.KEY_TYPE, Constant.NAMAL_TYPE_TAOBAO)
        }
        mAdapter = TeamAllowanceOrderAdapter(null,type)
        mRecyclerView.adapter = mAdapter
        getNewData()
    }

    override fun getNewData() {
        p.list(type,currentPage)
    }

    fun setData(data: MyTodayOrderInfo){
        (activity as TeamAllowanceOrderActivity).setData(data)
        if (currentPage == 1) {
            mSmartRefreshLayout.finishRefresh(true)
            if (data?.data != null && data.data.size > 0) {
                mAdapter.setNewData(data.data)
                mStatusManager.showContent()
            } else {
                mStatusManager.showEmpty()
            }
        } else {
            mSmartRefreshLayout.finishLoadMore(true)
            if (data.data == null || data.data.size == 0) {
                mSmartRefreshLayout.finishLoadMoreWithNoMoreData()
            } else {
                mAdapter.addData(data.data)
            }
        }
    }

    fun finishRefresh() {
        mSmartRefreshLayout.finishRefresh(true)
        mSmartRefreshLayout.finishLoadMore(true)
    }

}